package yogiro.service;

import java.sql.SQLException;
import java.util.ArrayList;

import yogiro.dao.MemberDAO;
import yogiro.to.AddressTO;
import yogiro.to.MemberTO;
import yogiro.to.PictureTO;
import yogiro.to.TourInfoTO;
import yogiro.to.ZipcodeTO;

public class MemberService {
	private MemberDAO memberDAO;
	public MemberService(MemberDAO memberDAO){
		this.memberDAO = memberDAO;
	}
	
	public MemberTO selectMemberById(String id)throws SQLException{
		MemberTO bto = memberDAO.selectMemberById(id);
		return bto;
	}
	public ArrayList<MemberTO> selectMemberList()throws SQLException{
		ArrayList<MemberTO> list = (ArrayList<MemberTO>)memberDAO.selectMemberList();
		return list;
	}
	public void updateMemberInfo(MemberTO mto)throws SQLException{

		memberDAO.updateMemberInfo(mto);
	}
	public void deleteMember(String id)throws SQLException{
		memberDAO.delete(id);
	}
	
	public void insertMember(MemberTO mto) throws SQLException{
		 memberDAO.insertMember(mto);
	}
	public ArrayList selectZipcodeByDong(String dong)throws SQLException{
		ArrayList<ZipcodeTO> list = (ArrayList<ZipcodeTO>) memberDAO.selectZipcodeByDong(dong);
		System.out.println("결과 동 : "+list);
		ArrayList address = new ArrayList();
		for(int i =0; i<list.size();i++  ){
			AddressTO ato = new AddressTO();
			String zipcode = (String)list.get(i).getZipcode();
			String sido = (String)list.get(i). getSido()+" ";			
			String gugun = (String)list.get(i).getGugun()+" ";
			String dong1 = (String)list.get(i).getDong()+" ";
			String bunji	= (String)list.get(i).getBunji();
			if(bunji==null){
				bunji = "";
			}
			String address1 = sido+gugun+dong1+bunji;
			ato.setAddress(address1);
			ato.setZipcode(zipcode);
			address.add(ato);
			System.out.println("변환 : "+address);
		}
		return address;
	}
	public ArrayList<TourInfoTO> selectTourRecommend(String tourWriterType) throws Exception{
		return memberDAO.selectTourRecommend(tourWriterType);
	}
	
	public PictureTO selectTourRecommend2(int pictureGroup) throws Exception{
		return memberDAO.selectTourRecommend2(pictureGroup);
	}
	public String selectMemberIdByMemberInfo(String birthday, int detail) throws SQLException{
		System.out.println("service : "+birthday+"||"+detail);
		String id = memberDAO.selectMemberIdByMemberInfo(birthday, detail);
		System.out.println("service:"+id);
		return id; 
	}
}






